class Admin::ConfigurationController < ApplicationController
  before_filter :authorize,:only=>['new','create','edit','update','destroy']
  layout "admin"
  def index
    @configurations = Configuration.find :all
  end
  
  
  def config_show
  
  end
  
  def config_num
  
  end
  
  def config_theme
    @app_theme = Configuration.find_by_name("theme")
    @thems = themes_file
  end 
  
#  def editor_config
#  
#  end
  
  def search_theme_directory
    Dir.glob("#{RAILS_ROOT}/public/themes/[-_a-zA-Z0-9 ]*").collect do |file|
      file if File.directory?(file)      
    end.compact
  end  
  
  def themes_file
      glob = "#{RAILS_ROOT}/public/themes/[-_a-zA-Z0-9 ]*"
      @theme_cache = Dir.glob(glob).select do |file|
      File.readable?("#{file}/about.theme")
      end.compact 
  end
# def update
#
#     Configuration.find_by_name("app_name").update_attribute("value",params[:app_name])
#     Configuration.find_by_name("app_url").update_attribute("value",params[:app_url])
#     Configuration.find_by_name("app_title").update_attribute("value",params[:app_title])
#     Configuration.find_by_name("app_subtitle").update_attribute("value",params[:app_subtitle])
#     
#     Configuration.find_by_name("about_authors").update_attribute("value",params[:about_authors])
#     Configuration.find_by_name("about").update_attribute("value",params[:about])
#     Configuration.find_by_name("powered_by").update_attribute("value",params[:powered_by])
#     
#     flash[:notice] = 'Configuration updata  succ...'
#     redirect_to :action => 'index'
##    @user = User.find(params[:id])
##    if @user.update_attributes(params[:user])
##      flash[:notice] = 'User was successfully updated.'
##      redirect_to :action => 'show', :id => @user
##    else
##      render :action => 'edit'
##    end
#  end
   def update
   params.each {|a| 
   @config = Configuration.find_by_name(a[0].to_s)
   @config.update_attribute("value",a[1]) if !@config.blank?
   }
   flash[:notice] = 'Configuration updata  succ...'
   redirect_to(:controller=>"admin/topic",:action => 'index')
   end
end
